const SYSTEM_INFO = uni.getSystemInfoSync()
const DEFAULT_HEIGHT = 40

export const getStatusBarHeight = () => SYSTEM_INFO.statusBarHeight || 0

export const getTitleBarHeight = () => {
	try {
		if (uni.getMenuButtonBoundingClientRect()) {
			const { top, height } = uni.getMenuButtonBoundingClientRect()
			const titleBarHeight = height + (top - getStatusBarHeight()) * 2
			return titleBarHeight
		} else {
			return DEFAULT_HEIGHT
		}
	} catch (err) {
		console.log(err)
	}
}

export const getNavBarHeight = () => {
	return getStatusBarHeight() + getTitleBarHeight()
}

export const getLeftIconLeft = () => {
	try {
		if (tt.getCustomButtonBoundingClientRect()) {
			const { leftIcon: { left, width } } = tt.getCustomButtonBoundingClientRect()
			return left + parseInt(width) + 5
		} else {
			return 0
		}
	} catch (err) {
		console.log(err)
	}
}
